package business_logic.game_elements;


import java.util.Collection;
import java.util.EnumSet;

import org.dom4j.DocumentHelper;
import org.dom4j.Element;


import business_logic.GameElement;
import business_logic.Tile;
import business_logic.view.GameViewIdentifier;
import model.elements.Exit;
import model.elements.attributes.Coordinate2D;
import model.exceptions.ModelExceptions;

public class Portal extends Exit implements GameElement{

	 private static final Collection<GameViewIdentifier> m_viewIdentifiers = 
	            EnumSet.of(GameViewIdentifier.SPRITE_PORTAL);
	
	public Portal(Coordinate2D position) throws ModelExceptions
	{
		super(position);
	}
	
	@Override
	public void vivir()
	{
	}

	@Override
	public boolean isAlive()
	{
		return true;
	}

	@Override
    public int getX()
    {
        return Tile.pixelToTile( m_currentPosition.getRealX() );
    }
    
    @Override
    public int getY()
    {
        return Tile.pixelToTile( m_currentPosition.getRealY() );
    }

	@Override
	public Collection<GameViewIdentifier> getViewIdentifiers() {
		return m_viewIdentifiers;
	}
	
    private static final long m_serialVersionUID = 1L;
    
    @Override
    public Element save()
    {
        Element elem = DocumentHelper.createElement( this.getClass().getName() );
        elem.addAttribute( "serialVersion", m_serialVersionUID+"" );
        elem.addAttribute( "x", Math.floor( this.getPosition().getRealX() ) +"" );
        elem.addAttribute( "y", Math.floor( this.getPosition().getRealY() ) +"" );
        
        return elem;
    }
    
    public Portal( Element elem ) throws ModelExceptions
    {
        super
        (
            new Coordinate2D
            (
                Double.parseDouble( elem.attributeValue("x") ),
                Double.parseDouble( elem.attributeValue("y") )
            )
        );
    }
}
